<?php  
class ControllerModuleArticleSearch extends Controller {
	protected function index() {
		$this->language->load('module/article_search');
		
    	$this->data['heading_title'] = $this->language->get('heading_title');
		
		
		$this->data['button_go'] = $this->language->get('button_go');
		$this->data['text_category'] = $this->language->get('text_category');
		$this->data['text_advanced'] = $this->language->get('text_advanced');
		$this->data['text_searchbox'] = $this->language->get('text_searchbox');
  
			$this->data['advanced'] = $this->url->link('news/search');
			
  		if (isset($this->request->get['filter_name'])) {
			$this->data['filter_name'] = $this->request->get['filter_name'];
		} else {
			$this->data['filter_name'] = $this->language->get('text_keyword');
		}
		if (isset($this->request->get['filter_article_category_id'])) {
			$this->data['filter_article_category_id'] = $this->request->get['filter_article_category_id'];
		} else {
			$this->data['filter_article_category_id'] = 0;
		}
		
		if (isset($this->request->get['article_category_id'])) {
			$this->data['article_category_id'] = $this->request->get['article_category_id'];
		} elseif (isset($this->request->get['cpath'])) {
			$path = explode('_', $this->request->get['cpath']);
		
			$this->data['article_category_id'] = end($path);
		} else {
			$this->data['article_category_id'] = '';
		}
		
		/* Categories Dropdown */
		
		$this->load->model('news/category');
		
		
		// 3 Level Category Search
		$this->data['categories'] = array();
					
		$categories_1 = $this->model_news_category->getCategories(0);
		
		foreach ($categories_1 as $category_1) {
			$level_2_data = array();
			
			$categories_2 = $this->model_news_category->getCategories($category_1['article_category_id']);
			
			foreach ($categories_2 as $category_2) {
				$level_3_data = array();
				
				$categories_3 = $this->model_news_category->getCategories($category_2['article_category_id']);
				
				foreach ($categories_3 as $category_3) {
					$level_3_data[] = array(
						'article_category_id' => $category_3['article_category_id'],
						'name'        => $category_3['name'],
					);
				}
				
				$level_2_data[] = array(
					'article_category_id' => $category_2['article_category_id'],	
					'name'        => $category_2['name'],
					'children'    => $level_3_data
				);					
			}
			
			$this->data['categories'][] = array(
				'article_category_id' => $category_1['article_category_id'],
				'name'        => $category_1['name'],
				'children'    => $level_2_data
			);
		}
		
		$this->data['sidebarsearch'] = array();
		
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/article_search.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/article_search.tpl';
		} else {
			$this->template = 'default/template/module/article_search.tpl';
		}
		
		$this->render();
	}
}
?>